package jvm.jtacck.db.records;


/**
 * 
 * @author Chris Gamble
 * 
 *         Represents an Item. An Item is the lowest form of a Specimen.
 *         Physically it contains a vial containing a sample of some sort, has a
 *         name of the sample, and the color of a cap. This representation has a
 *         unique identifier item_id, as well as the name and cap color.
 */
public class Item extends Record {
    
    private static final long serialVersionUID = 6864353390164895991L;
    public final int item_id;
    public final String name;
    public final String capColor;

    /**
     * Constructs an Item
     * 
     * @param id
     *            a unique identifier of the Item
     *            NON-NULLABLE
     * @param name
     *            the name of the Item
     * @param capColor
     *            The color of the cap the Item has
     */
    public Item(int id, String name, String capColor) {
        this.item_id = id;
        this.name = name;
        this.capColor = capColor;
    }
    
    @Override
    public boolean equals(Object o){
        if (o instanceof Item) {
            Item other = (Item) o; 
            return (item_id == other.item_id) &&
                   checkString(name, other.name) &&
                   checkString(capColor, other.capColor);
        }
        return false;
    }
    
    public boolean checkString(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        }else {
            return s1.equals(s2);
        }
    }
    
    @Override
    public int hashCode() {
        return item_id + name.hashCode() + 
        capColor.hashCode();
    }
    
    public String toString() {
        return item_id + ": " + name + ", " +  capColor + ".";
    }

}
